const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const Uglifyjs = require("uglifyjs-webpack-plugin");

module.exports = {
    mode:"production",  // development production
    entry:{
        "info":"./src/info/Info.js",  //运营信息
        "member-list":"./src/member/list/List.js",  //会员列表
        "red-list":"./src/red/list/List.js",  //红包列表
        "finance":"./src/finance/cash/Cash.js",  //提现列表
        "base-setting":"./src/setting/base/Base.js",  //基础设置
        "finance-setting":"./src/setting/finance/Finance.js",  //财务设置
        "profit-setting":"./src/setting/profit/Profit.js",   //盈利设置
        "media-setting":"./src/setting/media/Media.js",   //素材库设置
        "attention-setting":"./src/setting/attention/Attention.js",   //关注设置
        "message-setting":"./src/setting/message/Message.js",  //模板消息设置
        "other-setting":"./src/setting/other/Other.js",  //其他设置
        "media-check":"./src/media/check/Check.js",  //素材库素材审核
        "publish-person":"./src/publish/person/Person.js"
    },
    output:{
        path:path.dirname(__dirname)+'/kuyuan_red/dist/web/',
        filename:'[name].js',
        publicPath:'../addons/kuyuan_red/dist/web/'
    },
    plugins:[
        new CleanWebpackPlugin(),
        new ExtractTextPlugin("[name].css"),
        new Uglifyjs({
            test:/\.js/,
            uglifyOptions:{
                ecma:6
            },
            sourceMap:true
        })
    ],
    module:{
        rules:[
            {
                test:/\.(png|jpeg|jpg|gif|svg|eot|ttf|woff|woff2)$/,
                use:{
                    loader:'file-loader',
                    options:{
                        name:'image/[name]-[hash:6].[ext]'
                    }
                }
            },
            // {
            //     test:/\.css|less$/,
            //     use:["style-loader","css-loader","less-loader"]
            // }
            {
                test:/\.less$/i,
                use:ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use:[
                            {
                                loader:"css-loader"
                            },
                            {
                                loader:"less-loader",
                                options: {
                                    minimize: true
                                },
                            }
                        ],
                        publicPath:"./"
                })
            }
        ]
    },
    resolve:{
        alias:{
            'vue':'vue/dist/vue.common.js'
        }
    },
    optimization:{
        splitChunks:{
            name:"common",
            chunks:"initial"
        },
    }
}